package com.itheima.test.semaphore;

import java.util.concurrent.Semaphore;

public class MySemaphore implements Runnable{
    //获得管理员对象
    private Semaphore manger = new Semaphore(2);//同时允许两辆车通过
    @Override
    public void run() {
        //获得通行证
        try {
            manger.acquire();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //行驶
        System.out.println("开始行驶");
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("归还行驶证");
        //归还行驶证
        manger.release();
    }
}
